<template>
  <div id="login-wrapper">
    <div class="content">
      <h1>登录页面1236182763t7128371t273</h1>
      <el-form :model="form" label-width="auto" :rules="rules">
        <el-form-item label="用户名称" prop="username">
          <el-input 
            v-model="form.username" 
            placeholder="请输入用户名" 
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item label="用户密码" prop="password">
            <el-input
              v-model="form.password"
              style="width: 240px"
              type="password"
              placeholder="请输入密码"
              show-password
            />
          </el-form-item> 
      </el-form>
      <el-button type="primary" style="width: 150px;" @click="handleLogin">登录</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import { FormRules } from './types'
import { useRouter } from 'vue-router' 

// 获取路由实例
const router = useRouter()

const form = reactive({
  username: '',
  password: '',
})

const rules: FormRules = {
  username: [
    { required: true, message: '请输入用户名称', trigger: 'blur' },
    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' },
    { pattern: /^\S*$/, message: '用户名不能包含空格', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入用户密码', trigger: 'blur' },
    { min: 3, max: 8, message: '长度在 3 到 5 个字符', trigger: 'blur' },
    { pattern: /^\S*$/, message: '密码不能包含空格', trigger: 'blur' },
    // message: '密码至少包含大小写字母、数字、特殊字符，长度在 8 到 20 个字符', 特殊需求
    // pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*(),.?":{}|<>]).{8,20}$/,
  ],
}

async function handleLogin() {
  // 发送请求
  // 跳转路由
  router.push('/workspace')
}

</script>
<style lang="scss">
#login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
  background-color: lightpink;

  .content{
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    width: 400px;
    height: 500px;
    background-color: white;
    border-radius: 15%;
  }
}
</style>